<?php
/**
 * Contact form
 *
 * @category    IPB_CMS
 * @package     Application_Form
 * @copyright   Copyright (c) 2009 IPB CMS <http://ipb-cms.googlecode.com/>
 * @license     http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
 * @author      Henrique Moody <henriquemoody@gmail.com>
 */
class Form_Contact extends App_Form
{

    /**
     * Initialize form
     *
     * @return void
     */
    public function init()
    {
        // Name field
        $this->addElement('text', 'name', array(
            'label' => 'Name',
            'required' => true,
            'maxlength' => 45,
            'validators' => array(
                array('StringLength', array(3, 45))
            ),
            'filters' => array(
                'StringTrim'
            )
        ));
        // Email field
        $this->addElement('text', 'email', array(
            'label' => 'E-mail',
            'required' => true,
            'validators' => array(
                'EmailAddress'
            ),
            'filters' => array(
                'StringTrim'
            )
        ));
        // Subject field
        $this->addElement('select', 'subject', array(
            'label' => 'Subject',
            'multiOptions' => $this->_getSubjects(),
            'filters' => array(
                'StringTrim'
            )
        ));
        // Message field
        $this->addElement('textarea', 'message', array(
            'label' => 'Message',
            'required' => true,
            'validators' => array(
                array('StringLength', array(3, 8000))
            ),
            'filters' => array(
                'StringTrim',
                array('Callback', array(
                    'callback' => 'nl2br'
                ))
            )
        ));
        // Submit buttom
        $this->addElement('submit','submit', array(
            'label' => 'Send',
            'ignore' => true,
            'decorators' => array(
                'ViewHelper',
                array('HtmlTag', array('tag' => 'dd',
                                       'id' => 'submit-element'))
            )
        ));
        // CSRF protection field
        if (APPLICATION_ENV != 'testing') {
            $this->addElement('hash', 'token', array(
                'ignore' => true,
                'decorators' => array(
                    'ViewHelper',
                    array('HtmlTag', array('tag' => 'dd',
                                           'id' => 'token-element')),
                )
            ));
        }
    }

    /**
     * Creates a array of subjects for this form
     *
     * @return array List of subjects
     */
    protected function _getSubjects()
    {
        $data = array();
        $data[0] = 'Choose the message subject';
        $data[1] = 'Request player';
        $data[2] = 'Question';
        return $data;
    }

}
